
<div class="x_panel">
  <div class="x_content" style="display: block;">
    <!--表格主体内容-->
    <div class="row-fluid">
      <form action="/goods/on.html" method="get">
        <label class="control-label">SPUID</label>
        <input type="text" class="form-control-new" name="form[spuid]" value="{if isset($query.spuid)}{$query.spuid}{/if}">
        <label class="control-label">商品名称</label>
        <input type="text" class="form-control-new" name="form[goods_name]" value="{if isset($query.goods_name)}{$query.goods_name}{/if}">
        <label class="control-label">状态</label>
        <select  class="form-control-new" name="form[can_buy]" >
          <option {if !isset($query.can_buy) || $query.can_buy==-1}selected="selected"{/if} value="-1">全部</option>
          <option {if isset($query.can_buy) && $query.can_buy==1}selected="selected"{/if} value="1">可用</option>
          <option {if isset($query.can_buy) && $query.can_buy==0}selected="selected"{/if} value="0">不可用</option>
        </select>

        <label class="control-label">一级类目</label>
        <select id="first_category" class="form-control-new" name="form[first_category]" >
          <option {if !isset($query.first_category) || $query.first_category=="0"}selected="selected"{/if} value="0">全部</option>
          {foreach $local_search_first_category AS $value1}
          <option {if isset($query.first_category) && $query.first_category==$value1.category_id}selected="selected"{/if} value="{$value1.category_id}">{$value1.category_name}</option>
          {/foreach}
        </select>
        <label class="control-label">二级类目</label>
        <select id="second_category" class="form-control-new" name="form[second_category]" >
          <option {if !isset($query.second_category) || $query.second_category=="0"}selected="selected"{/if} value="0">全部</option>
          {if isset($goods.second_category) && $goods.second_category}
          {foreach $goods.second_category AS $value2}
          <option {if isset($query.second_category) && $query.second_category==$value2.category_id}selected="selected"{/if} value="{$value2.category_id}">{$value2.category_name}</option>
          {/foreach}
          {/if}
        </select>

        <label class="control-label">推荐产品</label>
        <select  class="form-control-new" name="form[ishotornew]" >
          <option {if !isset($query.ishotornew) || $query.ishotornew==0}selected="selected"{/if} value="0">全部</option>
          <option {if isset($query.ishotornew) && $query.ishotornew==1}selected="selected"{/if} value="1">Banner下</option>
          <option {if isset($query.ishotornew) && $query.ishotornew==2}selected="selected"{/if} value="2">底部</option>
        </select>
        <button type="submit" class="btn btn-primary" >查询</button>
      </form>

      <input id="spuid" name="spuid" type="hidden" value="">
      <button id="batch_off" type="submit" class="btn btn-primary" >批量下架</button>

    </div>
    <br>
    <div class="cont">
      <table class="table table-bordered table-striped">
        <thead>
        <tr>
          <th width="100px"></th>
          <th width="100px">SPU ID</th>
          <th>商品名称</th>
          <th>图片</th>
          <th>商品描述</th>
          <th>类目</th>
          <!--<th>严选价格</th>
          <th>合约价格</th>
          <th>销售价格</th>-->
          <th>总销量</th>
          <th>商品状态</th>
          <th>推荐位置</th>
          <th>排序</th>
          <th>操作</th>
        </tr>
        </thead>
        <tbody>
        {foreach $goods.lists as $goodsitem}
        <tr>
          <td><input type="checkbox" name="form[goods_id]" value="{$goodsitem.goods_id}"/></td>
          <td>{$goodsitem.yx_goods_id}</td>
          <td>{$goodsitem.goods_name}</td>
          <td><img src="../{$goodsitem.goods_pic}" width="50px" height="50px" /> </td>
          <td width="200px">{$goodsitem.simple_desc}</td>
          <td>
            {if isset($goodsitem.first_category_name)}一级类目:{$goodsitem.first_category_name}{/if}
            {if isset($goodsitem.second_category_name)}<br/>二级类目:{$goodsitem.second_category_name}{/if}
          </td>
          <!--<td>{$goodsitem.yanxuan_price}</td>
          <td>{$goodsitem.channel_price}</td>
          <td>{$goodsitem.goods_price}</td>-->
          <td>{$goodsitem.sales_volume}</td>
          <td>{if $goodsitem.can_buy==0}不可用{else}可用{/if}</td>
          <td>{if $goodsitem.is_hot}Banner下{elseif $goodsitem.is_new}底部{else}无推荐{/if}</td>
          <td>{$goodsitem.goods_sort}</td>
          <td>
            <div class="x_content">
              <a class="btn btn-primary btn-xs" href="{eval U(['goods/sku-detail-by-id','id'=>$goodsitem.goods_id])}"> 查看SKU</a>
              <button class="recommend btn btn-primary btn-xs" data-title="{$goodsitem.goods_name}" data-goodsid="{$goodsitem.goods_id}" data-ishot="{$goodsitem.is_hot}" data-isnew="{$goodsitem.is_new}" data-sort="{$goodsitem.goods_sort}">推荐</button>
<div>
              <button class="btn btn-danger btn-xs" data-toggle="dropdown">取消推荐
                <i class="icon-angle-down"></i></button>
              <ul class="dropdown-menu">
                <li><a href="{eval U(['goods/off-recommend','id'=>$goodsitem.goods_id])}">确定</a></li>
                <li><a href="javascript:;">取消</a></li>
              </ul>
</div>
              <div>
              <button class="btn btn-danger btn-xs" data-toggle="dropdown">下架
                <i class="icon-angle-down"></i></button>
              <ul class="dropdown-menu">
                <li><a href="{eval U(['goods/off','id'=>$goodsitem.goods_id])}">确定</a></li>
                <li><a href="javascript:;">取消</a></li>
              </ul>
              </div>

            </div>
          </td>
        </tr>
        {/foreach}
        </tbody>
      </table>
      <!--分页-->
      {Yii::$app->view->render('/com/pager.php',['pager'=>$goods.pager])}

    </div>




  </div>
</div>


<div class="modal fade bs-example-modal-lg" tabindex="-1" role="dialog" aria-hidden="true" id="detail-modal">
  <div class="modal-dialog modal-lg">
    <div class="modal-content">
      <div class="modal-header" style="border:none">
        <button type="button" class="close" data-dismiss="modal"><span aria-hidden="true">×</span></button>
        <h4 class="modal-title" id="myModalLabel"></h4>
      </div>
      <div class="modal-body">
        <div class="loaders">
          <div class="ball-spin-fade-loader">
            <!--商品名称：<span id="goods_name"></span><br>-->
            推荐位置:<select required="required" id="ishotornew">
              <option value="0" selected="selected">请选择</option>
              <option value="1">Banner下</option>
              <option value="2">底部</option>
            </select>
            <br>
            推荐排序：<input required="required" id="goods-sort" type="text" value="" />
          </div>
        </div>
        <div id="modal-dyn"></div>
      </div>
      <div class="modal-footer" style="border:none;">
        <button id="recommendsumbit" type="button" class="copy btn btn-secondary" data="">提交</button>
        <button type="button" class="btn btn-secondary" data-dismiss="modal">关闭</button>
      </div>
    </div>
  </div>
</div>

<script>
    $('#first_category').change(function (e) {
        var category_id = this.value;
        var url = "{['goods/get-second-category-by-id']|U}";
        $.post(url, 'category_id='+category_id, function (data) {
            $('#second_category').html('');
            $('#second_category').append('<option selected="selected" value="0">全部</option>');
            for(var i=0; i<data.length; i++){
                $('#second_category').append("<option value= '"+data[i].category_id+"'>"+data[i].category_name+"</option>");
            }
        },'json');
    })

    $("#batch_off").click(function (e){
        /*var goods_ids = $("input[type='checkbox']").val();
        console.log(goods_ids);*/
        var arr = new Array();
        $('input:checkbox').each(function(i) {
            if($(this).is(":checked")) {
                arr[i] =$(this).val();
            }
        });
        var vals = arr.join(",");
        if(vals){
            if (confirm("您确定要下架这些商品吗")==true){
                var url = "{['goods/batch-off']|U}";
                $.post(url, 'goods_ids='+vals, function (data) {
                    if(data.status){
                        alert("批量下架成功");
                        window.location.reload();
                    }else {
                        alert("批量下架失败");
                    }

                },'json');
                return true;
            }else{
                return false;
            }

            //window.location.href = "batch-on.html?yx_goods_ids="+vals;
        }
    })

    $(".recommend").click(function () {
        $('#recommendsumbit').attr('data',$(this).attr('data-goodsid'));
        $('#myModalLabel').text($(this).attr('data-title'));

        if($(this).attr('data-ishot')==1){
            $('#ishotornew').val(1)
        }else if($(this).attr('data-isnew')==1){
            $('#ishotornew').val(2)
        }else{
            $('#ishotornew').val(0)
        }

        $('#goods-sort').val($(this).attr('data-sort'));

        $('#detail-modal').modal('show');
    })

    $("#recommendsumbit").click(function () {
        var goods_id = $(this).attr('data');
        var goods_ishotornew = $('#ishotornew').val();
        var goods_sort = $('#goods-sort').val();
        var url = "{['goods/recommend']|U}";
        $.post(url, 'goods_id='+goods_id+'&goods_ishotornew='+goods_ishotornew+'&goods_sort='+goods_sort, function (data) {
            window.location.reload();
        },'json');
        $('#detail-modal').modal('hide');
    })

</script>
